# printing the first 5 rows of the dataset
print(df.head())

# Let's visualize the distribution of the penguins species with a bar plot in matplotlib
import matplotlib.pyplot as plt
species_count = df['Species'].value_counts()
plt.figure(figsize=(10, 6))
species_count.plot(kind='bar', color='skyblue')
plt.title('Distribution of Penguin Species')
plt.xlabel('Species')
plt.ylabel('Count')
plt.xticks(rotation=45)
plt.show()

# Let's visualize with boxplots how the FlipperLength, CulmenLength and CulmenDepth are distributed for each species
# importing seaborn
import seaborn as sns
sns.boxplot(x='Species', y='FlipperLength', data=df)
plt.title('FlipperLength Distribution by Species')
plt.show()
sns.boxplot(x='Species', y='CulmenLength', data=df)
plt.title('CulmenLength Distribution by Species')
plt.show()
sns.boxplot(x='Species', y='CulmenDepth', data=df)
plt.title('CulmenDepth Distribution by Species')
plt.show()

# Show rows with missing values
print(df[df.isnull().any(axis=1)])

# Drop rows with missing values
df.dropna(inplace=True)

# Let's prepare for training:
# 1. Split the data into features and labels
# 2. Split the data into training and test sets

# Split the data into features and labels
# features are CulmenLength, CulmenDepth, FlipperLength
# labels are Species
X = df[['CulmenLength', 'CulmenDepth', 'FlipperLength']]
y = df['Species']

# Split the data into training and test sets in a way to have 30% of the data for testing
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42)

# Let's train a Logistic Regression model
# 1. Create a multiclass Logistic Regression model
# 2. Train the model

# Create a multiclass Logistic Regression model
from sklearn.linear_model import LogisticRegression
model = LogisticRegression(multi_class='multinomial', solver='lbfgs')

# Train the model
model.fit(X_train, y_train)

# Let's evaluate the model
# 1. Predict the labels of the test set
# 2. Calculate the accuracy of the model

# Predict the labels of the test set
y_pred = model.predict(X_test)

# Calculate the accuracy of the model
from sklearn.metrics import accuracy_score
accuracy = accuracy_score(y_test, y_pred)
print(f"Accuracy: {accuracy}")